home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / pmcstex.zip / CZECH_PM.ZIP / CZECH_PM.E next >
Text File  |  1996-02-12  |  8KB  |  303 lines

  1. /*
  2. Uprava -- P. Mikulík:        //PM   <- tohle jsou me znacky
  3.   - zapoznamkoval jsem Beepy //PM
  4.   - pridal jsem univerzalni konstantu czech_is nesouci informaci //PM
  5.     o aktualnich keys (potreboval jsem to pri prepinani recke klavesnice //PM
  6.     a nevim, jestli jde aktualni nastaveni klaves nejak ulozit //PM
  7.  
  8. This is Czech.E 1.01 as of 27 Dec 1995 13:55:12 
  9. Copyright (C) Z. Wagner -- Ice Bear Soft
  10.  
  11. This is the E-macro file supporting Czech and Slovak keyboard in EPM. It was developed and
  12. tested with EPM 6.03, it is not sure whether it may work with other versions. No version 
  13. check is made.
  14.  
  15. This file is provided AS IS without any warranty expressed or implied. Use it on your own 
  16. risk.
  17.  
  18. The file is distributed in the hope that it can be useful for you.
  19.  
  20. You are allowed to use this and accompanying files on unlimited number of your 
  21. computers. You are allowed to distribute this file provided you do not take money fo the 
  22. distribution except of nominal charge for hadling, diskettes, postage, etc. and it is 
  23. distributed together with all files mentioned in CzEpmCs.inf and EngEpmCs.inf, preferably 
  24. as a single ZIP-file. You are allowed to modify the file for your own use. You are
  25. allowed to distribute the modified versions provided the modifications are clearly marked
  26. and any user can obtain the original file on demand. It is strongly suggested to use
  27. "compile if" and/or "tryinclude" directives for modifications so that the original version
  28. could easily be restored.
  29.  
  30. There is no official support for bug fixes. The author does not guarantee that the bugs 
  31. will ever be corrected. However, the bug reports are invited and the author will correct 
  32. problems bothering him. You can also send your modifications, some of them could become 
  33. "standard" if the next version will ever be released.
  34.  
  35. Remember that this is only temporary non-system solution since it is easier to develop and
  36. the national keyboard is most important in the editor and "relatively unimportant" in 
  37. other applications.
  38. */
  39.  
  40. define CZversion = "1.01"
  41. define WANT_CS_DEFAULT=0 -- Set to 1 if you want CS keyboard as default
  42. define WANT_NUM_UPCASE=1 -- Set to 0 if you do not like CapsLock with nums
  43. define dead_key="`" -- the dead key
  44. define SWAP_ZY = 0  -- swaps ZY if set to 1
  45. define WANT_GUESS_WORD = 1 -- Set to 0 if you do not like the Guess Word function
  46.                            -- This function is invoked by Alt/=
  47.  
  48. tryinclude 'MyCzech.E' -- for your configuration
  49.  
  50. ; Returns the version number
  51. DEFPROC CzechVersion() =
  52. return CZversion
  53.  
  54. DEFC CzechVersion = message('Czech.E Version' CzechVersion())
  55.  
  56. DEFKEYS czech_switch -- defines switch to the Czech/Slovak key set
  57. def a_leftbracket = SwitchToCzech()
  58. COMPILE IF WANT_GUESS_WORD
  59. def a_equal = GuessWord()
  60. COMPILE ENDIF
  61.  
  62. ; The following procedure switches to the Czech/Slovak key set
  63. DEFPROC SwitchToCzech() =
  64. universal dead_cnt
  65. universal czech_is; czech_is=1; -- //PM
  66. dead_cnt = 0
  67. keys czech_keys
  68. ;Beep(880, 300)
  69.  
  70. ; The following procedure switches back
  71. DEFPROC SwitchBack() =
  72. universal dead_cnt
  73. universal czech_is; czech_is=2; -- //PM
  74. dead_cnt = 0
  75. keys czech_switch
  76.  
  77. ; Initialization
  78. DEFINIT
  79. COMPILE IF WANT_CS_DEFAULT
  80. universal czech_is; czech_is=1; -- //PM
  81. SwitchToCzech()
  82. COMPILE ELSE
  83. universal czech_is; czech_is=2; -- //PM
  84. SwitchBack()
  85. COMPILE ENDIF
  86.  
  87. ; Constants for numbers
  88. define KS_DOWNTOGGLE = 2
  89. define KS_UPTOGGLE = 4
  90. define VK_CAPSLOCK = 14
  91.  
  92. ; The definitions for the Czech/Slovak key set
  93. DEFKEYS czech_keys
  94. def a_rightbracket = SwitchBack()
  95. ;                     Beep(440, 450)
  96. def '0'-'9' = CzechNum()
  97. def space = CzechSpace()
  98. def \33-\47, \58-\126 = CzechKeys()
  99. def a_8 = num2cs()
  100. def a_9 = cs2num()
  101. COMPILE IF WANT_GUESS_WORD
  102. def a_equal = GuessWord()
  103. COMPILE ENDIF
  104.  
  105. ; Error beep
  106. DEFPROC ErrorBeep() =
  107. ; Beep(512,150)
  108.  
  109. const 
  110. compile if not defined(cz_nums)
  111.   cz_nums =   "à╪τƒ²º∞áíé",
  112. compile endif
  113.   real_nums = "1234567890"
  114.  
  115. ; Deal with numbers on the alphanumeric keyboard
  116. DEFPROC CzechNum()
  117. universal dead_cnt
  118. if dead_cnt then
  119. dead_cnt = 0
  120. ErrorBeep()
  121. endif
  122. parse value lastkey(2) with flags 3 repeat 4 scancode 5 charcode 7 vk
  123. scan = asc(scancode)
  124. if scan >= 2 and scan <= 11 then
  125.   COMPILE IF WANT_NUM_UPCASE
  126.     ch = substr(cz_nums, scan-1, 1)
  127.     caps = getkeystate(VK_CAPSLOCK)
  128.     if caps == KS_DOWNTOGGLE or caps == KS_UPTOGGLE then
  129.       keyin upcase(ch)
  130.     else
  131.       keyin ch
  132.     endif
  133.   COMPILE ELSE
  134.     keyin substr(cz_nums, scan-1, 1)
  135.   COMPILE ENDIF
  136. else
  137.   keyin lastkey()
  138. endif
  139.  
  140. ; Conversion á to 8
  141. DEFPROC cs2num() =
  142. universal cs_dir
  143. cs_dir = 1
  144. call CsConvert()
  145.  
  146. ; Conversion 8 to á
  147. DEFPROC num2cs() =
  148. universal cs_dir
  149. cs_dir = 0
  150. call CsConvert()
  151.  
  152. ; Conversion body
  153. DEFPROC CsConvert() =
  154. universal cs_dir
  155. if checkmark()==0 then
  156.   ErrorBeep()
  157.   sayerror 'No mark'
  158. else
  159.   display -1
  160.   psave_pos(cs_pos)
  161.   mt = marktype()
  162.   getmark first_line, last_line, first_col, last_col, mark_fileid
  163.   for linenum = first_line to last_line
  164.     getline line, linenum
  165.     len = length(line)
  166.     if (mt=='CHAR' and linenum==first_line) or mt=='BLOCK' then
  167.       a = first_col
  168.     else
  169.       a = 1
  170.     endif
  171.     if (mt=='CHAR' and linenum==last_line) or mt=='BLOCK' then
  172.       z = min(last_col, len)
  173.     else
  174.       z = len
  175.     endif
  176.     stg = substr(line, a, z-a+1)
  177.     if cs_dir then
  178.       stg = translate(stg, real_nums, cz_nums)
  179.     else
  180.       stg = translate(stg, cz_nums, real_nums)
  181.     endif
  182.     if a==1 and z==len then
  183.       repline = stg
  184.     elseif a == 1 then
  185.       repline = stg || substr(line, z+1, len-z)
  186.     else
  187.       repline = substr(line, 1, a-1) || stg || substr(line, z+1, len-z)
  188.     endif
  189.     replaceline repline, linenum
  190.   endfor
  191.   prestore_pos(cs_pos)
  192.   display 1
  193. endif
  194.  
  195. ; Prints the dead key
  196. DEFPROC CzechSpace() =
  197. universal dead_cnt
  198. if dead_cnt then
  199.   for cnt = 1 to dead_cnt
  200.     keyin dead_key
  201.   endfor
  202.   dead_cnt = 0
  203. else
  204.   keyin ' '
  205. endif
  206.  
  207. const
  208. compile if not defined(orig)
  209.   orig = "AaCcDdEeIiLlNnOoRrSsTtUuYyZz<>"
  210. compile endif
  211. compile if not defined(dd1)
  212.   dd1  = "╡áÅå╥╘Éé╓íæÆπΣαóΦΩùÿ¢£Θúφ∞콫»"
  213. compile endif
  214. compile if not defined(dd2)
  215.   dd2  = "╢⼃╥╘╖╪╫îòû╒σΓôⁿ²µτ¢£▐àYyªº«»"
  216. compile endif
  217. compile if not defined(dd3)
  218.   dd3  = "ÄäÇçDd╙ëIi¥êNnÖö⌡⌡ßßTtÜüYyZz«»"
  219. compile endif
  220.  
  221. ; Other defined keys
  222. DEFPROC CzechKeys() =
  223. universal dead_cnt
  224. ch = lastkey()
  225. COMPILE IF SWAP_ZY
  226.   ch = translate(ch, 'zZyY', 'yYzZ')
  227. COMPILE ENDIF
  228. if ch == dead_key then
  229.   dead_cnt = dead_cnt + 1
  230.   if dead_cnt == 4 then
  231.     keyin dead_key
  232.     dead_cnt = 0
  233.     ErrorBeep()
  234.   endif
  235. else
  236.   if dead_cnt then
  237.     c = ch
  238.     if dead_cnt == 1 then
  239.       ch = translate(c, dd1, orig)
  240.     elseif dead_cnt == 2 then
  241.       ch = translate(c, dd2, orig)
  242.     elseif dead_cnt == 3 then
  243.       ch = translate(c, dd3, orig)
  244.     else
  245.       ErrorBeep();  sayerror 'this cannot happen'
  246.     endif
  247.     if c == ch then
  248.       ErrorBeep() -- Invalid composite
  249.     endif
  250.     dead_cnt = 0
  251.   endif
  252.   keyin ch
  253. endif
  254.  
  255. -- Guess Word
  256. COMPILE IF WANT_GUESS_WORD
  257. DEFPROC GuessWord() =
  258. display -1
  259. -- Save the cursor position
  260. psave_pos(sv_pos)
  261. call pbegin_word()
  262. wb_line = .line;   wb_col = .col
  263. call pend_word()
  264. we_line = .line;   we_col = .col
  265. if wb_line <> we_line or we_col < wb_col then
  266.   ErrorBeep()
  267.   prestore_pos(sv_pos)
  268.   display 1 
  269.   return
  270. endif
  271. call pbegin_word()
  272. getline line, wb_line
  273. wd = substr(line, wb_col, we_col-wb_col+1)
  274. if strip(wd) == '' then
  275.   ErrorBeep()
  276.   prestore_pos(sv_pos)
  277.   display 1 
  278.   return
  279. endif
  280. getsearch sv_search
  281. rc = 0
  282. 'L [ \t\n\.,><;:''`"\[\]\{\}\(\)!/\*\-\+^]'wd'-xre'
  283. if rc <> 0 then
  284.   ErrorBeep()
  285.   setsearch sv_search
  286.   prestore_pos(sv_pos)
  287.   display 1 
  288.   return
  289. endif
  290. ws_line = .line;   ws_col = .col+1
  291. pend_word()
  292. wse_col = .col
  293. getline s_line, ws_line
  294. wdx = substr(s_line, ws_col, wse_col-ws_col+1) 
  295. .line = wb_line;   .col=wb_col
  296. 'C 'wd''wdx
  297. prestore_pos(sv_pos)
  298. .line = wb_line;   .col=wb_col
  299. pend_word();   right
  300. setsearch sv_search
  301. display 1
  302. COMPILE ENDIF
  303.